//
//  DSZSettingViewController.m
//  7.13苏宁框架
//
//  Created by app05 on 15/7/17.
//  Copyright (c) 2015年 lovena. All rights reserved.
//

#import "DSZSettingViewController.h"
#import "DSZStyleOneCell.h"
#import "DSZNavigationBarView.h"
#import "DSZMoreView.h"
#import "DSZSwitchTableViewCell.h"

#import "DSZGuanYuViewController.h"
#import "DSSuNingJiaZuViewController.h"
#import "DSZDiZhiXianShiViewContrller.h"

#import "DSZMainViewController.h"
#import "HomeViewController.h"
#import "DSZShopViewController.h"
@interface DSZSettingViewController ()<UITableViewDataSource,UITableViewDelegate,navigationBarDelegata,tableViewIndexPathRowDelegate>

@property(nonatomic,weak)UIView *moreView;
@property(nonatomic,assign)BOOL flag;
@property(nonatomic,weak)UITableView *tableView;

@end

@implementation DSZSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    self.view.frame=CGRectMake(0, 0, 320, 480);
    
    [self addNavBar];
    
   [self addContentView];
    
//    //开启模量模式
//    NSUserDefaults *d=[NSUserDefaults standardUserDefaults];
    
    
}
-(void)viewWillAppear:(BOOL)animated
{
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *str =[defaults objectForKey:@"zh2"];
    if ([str isEqualToString:@"disizu"]) {
        [self loadNewBtn];
    }
    else
    {
        
    }
    
    DSZMainViewController *main=(DSZMainViewController*)self.tabBarController;
    [main hiddenMainTabbar:YES];
    self.navigationController.navigationBar.alpha=0;
}
-(BOOL)prefersStatusBarHidden{
    return YES;
}
-(void)addNavBar
{
    DSZNavigationBarView *nav=[[DSZNavigationBarView alloc]initWithFrame:CGRectZero];
    nav.frame=CGRectMake(0, 20, 320, 44);
    [self.view addSubview:nav];
    nav.delegate=self;
    nav.titleLabel=@"设置";
}
-(void)addContentView
{
    UITableView *tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 64, 320, 315)];
    tableView.backgroundColor=[UIColor clearColor];
    [self.view addSubview:tableView];
    tableView.delegate=self;
    tableView.dataSource=self;
    tableView.scrollEnabled=NO;
    _tableView=tableView;
}

//加载一个新的btn
-(void)loadNewBtn
{
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame=CGRectMake(10, 390, 300, 40);
    [btn setBackgroundImage:[UIImage imageNamed:@"shopcart_goaround_btn_press"] forState:UIControlStateNormal];
    [btn setTitle:@"退出登录" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(unLogin) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    [self.view bringSubviewToFront:btn];
    
}
// 点击事件
-(void)unLogin
{
    // 存储数据
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    [defaults setObject:@"" forKey:@"zh2"];
    [defaults setObject:@"" forKey:@"mm"];
    [defaults synchronize];
    
    [self.navigationController popViewControllerAnimated:YES];

    
}
-(void)btnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)moreBtnClick
{
    
    if (!self.flag) {
        DSZMoreView *more=[DSZMoreView moreView];
        more.delegate=self;
        more.frame=CGRectMake(185, 65, 146, 186);
        self.moreView=more;
        [self.view addSubview:self.moreView];
        self.flag=YES;
    }
    else
    {
        [self.moreView removeFromSuperview];
        self.moreView=nil;
        self.flag=NO;
    }
}
-(void)dszMoreViewWithIndexRow:(NSInteger)indexPathRow
{
    if (indexPathRow==0) {
        UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        DSZMainViewController *main=[story instantiateViewControllerWithIdentifier:@"main"];
        //DSZMainViewController *main=[[DSZMainViewController alloc]init];
        [self presentViewController: main animated:NO completion:nil];
    }else if (indexPathRow==1)
    {}
    else if (indexPathRow==2)
    {
        UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        
        DSZShopViewController *shop=[story instantiateViewControllerWithIdentifier:@"shop"];
        [self.navigationController pushViewController:shop animated:NO];
        self.flag=YES;
        [self moreBtnClick];
         DSZMainViewController *main=(DSZMainViewController*)self.tabBarController;
        [main hiddenMainTabbar:YES];
    }else if (indexPathRow==3)
    {
        [self.navigationController popToRootViewControllerAnimated:YES];
   
    }
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;
}
-(NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0) {
        return 1;
    }else if (section==1)
        return 2;
    else if (section==2)
        return 1;
    else if (section==3)
        return 1;
    else
        return 1;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=nil;
    if (indexPath.section==0&&indexPath.row==0) {
        DSZStyleOneCell *cellOne=[DSZStyleOneCell cell5];
        cell=cellOne;
    }else if (indexPath.section==1){
        if (indexPath.row==0) {
            DSZSwitchTableViewCell *swith=[DSZSwitchTableViewCell cell];
            cell=swith;
        }else{
            DSZStyleOneCell *cellOne=[DSZStyleOneCell cell7];
            cell=cellOne;
        }
    }else if (indexPath.section==2&&indexPath.row==0)
    {
        DSZStyleOneCell *cellOne=[DSZStyleOneCell cell8];
        cell=cellOne;
    }else if (indexPath.section==3&&indexPath.row==0)
    {
        DSZStyleOneCell *cellOne=[DSZStyleOneCell cell9];
        cell=cellOne;
    }else if(indexPath.section==4&&indexPath.row==0){
        DSZStyleOneCell *cellOne=[DSZStyleOneCell cell10];
        cell=cellOne;
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 18;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==2&&indexPath.row==0) {
        return 58;
    }
    return 34;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section ==0&&indexPath.row==0) {
        DSZDiZhiXianShiViewContrller *dzgl=[[DSZDiZhiXianShiViewContrller alloc]init];
        [self.navigationController pushViewController:dzgl animated:YES];
        self.navigationController.navigationBar.alpha=1;
    }
    else if(indexPath.section==1&&indexPath.row==1)
    {
        UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"提示" message:@"您确定要清除图片缓存？" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alertView show];
   
    }
    else if(indexPath.section==3&&indexPath.row==0)
    {
        DSZGuanYuViewController *dzgl=[[DSZGuanYuViewController alloc]init];
        [self.navigationController pushViewController:dzgl animated:YES];
        self.navigationController.navigationBar.alpha=1;
    }
    else if(indexPath.section==4&&indexPath.row==0)
    {
        DSSuNingJiaZuViewController *dzgl=[[DSSuNingJiaZuViewController alloc]init];
        [self.navigationController pushViewController:dzgl animated:YES];
        self.navigationController.navigationBar.alpha=1;
    }
    
}
@end
